package vip.websky.project.web.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import vip.websky.project.common.error.CommonsRuntimeException;
import vip.websky.project.common.error.ErrorCode;
import vip.websky.project.common.error.ErrorMessage;
import vip.websky.project.module.dto.ResponseDTO;
import vip.websky.project.module.entity.user.SysPermission;
import vip.websky.project.module.entity.user.SysUser;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 首页
 *
 * @Author YangYong E-mail:yang2048@qq.com
 * @Create 2017/8/28-19:30
 */
@Controller
@Slf4j
public class IndexController extends BaseController {


    /**
     * 1.获取菜单信息
     *
     * @param request
     * @param response
     */
    @RequestMapping(value = "/index/getMenuInfo", method = {RequestMethod.GET})
    public void getMenuInfo(HttpServletRequest request, HttpServletResponse response) {
        ResponseDTO<List<SysPermission>> result = new ResponseDTO<>();

        try {

            result.setResult(null);
        } catch (CommonsRuntimeException e) {
            result.setStatusCode(e.getCode());
            result.setStatusMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("异常信息:{}", e);
            result.setStatusCode(ErrorCode.UNEXPECTED_ERROR);
            result.setStatusMessage(ErrorMessage.UNEXPECTED_ERROR);
        } finally {
            sendMessages(request, response, result);
        }
    }

    @RequestMapping(value = {"/to_index", "", "/"}, method = RequestMethod.GET)
    public String index(HttpServletRequest request) {
        SysUser userInfo = (SysUser) getSessionObject(request, "y");//session中获取登录用户信息
        if (userInfo != null) {
            return "/index";
        } else {
            return "/index";
        }
    }

    @RequestMapping(value = {"/to_main"}, method = RequestMethod.GET)
    public String main() {
        return "/main";
    }

    @RequestMapping(value = {"/to_login"}, method = RequestMethod.GET)
    public String login() {
        return "/login";
    }

    @RequestMapping(value = {"/test"}, method = RequestMethod.GET)
    public String test() {
        return "/user/test";
    }
}
